package com.leetcode;

@SuppressWarnings("all")
public class L0169 {
    public static void main(String[] args) {
        int[] arr={8,8,7,7,7};
        System.out.println(majorityElement(arr));
    }
    public static int majorityElement(int[] nums) {
      int x = 0,count=0;
        for (int num : nums) {
            if (count==0){
                x=num;
                count++;
            }else{
                if (x==num)
                    count++;
                else
                    count--;
            }
        }
        return x;
    }
}
